// scaup - Scala up!
// (c) 2008-2009, Normen Müller, normen.mueller@gmail.com  
// $Id: DM.scala 2524 2009-10-26 11:16:21Z nmueller $
package locutor.model.parsing.dm

import java.io.File
import java.text.MessageFormat.{format}

import scaup.Views._

/** This object provides a simple interface to the DM parser class.
 * 
 * @author <a href="mailto:normen.mueller@googlemail.com">Normen M&#xFC;ller</a>
 * @version 0.0.5 */
object DM extends Parser {
  def apply(input: File): TR =
    if(input == null || !(input exists))
      throw new Exception(format("Physical DM file may not be null (''{0}'').", input))
    else apply(input.content)
  
  def apply(input: String): TR =
    if(input == null)
      throw new Exception("Physical DM representation may not be null.")
    else parse(input)
  
  def parse(input: String) = phrase(dm)(new lexical.Scanner(input)) match {
    case Success(result, _) => result
    case n@_                => throw new Exception(format("DM parsing error in ''{0} ...}''\n", input.lines.next) + n)
  }
}
